home *** CD-ROM | disk | FTP | other *** search
- /* shiftMod.c 2 July 1987
- *
- * by Mike Scanlin and Andy Voelker
- *
- * Installs a tail patch on _GetNextEvent so that the Shift key toggles
- * between upper and lower case letters if the Caps Lock key is down.
- *
- * No toggle is done if the option and/or command key was held down.
- *
- */
-
- #include "Asm.h"
- #include "EventMgr.h"
-
- #define what OFFSET(EventRecord,what)
- #define message OFFSET(EventRecord,message)
- #define modifiers OFFSET(EventRecord,modifiers)
-
- #define GetNextEvent 0xA970
- #define JMP 0x4EF9
- #define memFullErr -108
-
- void main(void); /* prototype for main() */
-
- void main()
- {
- asm {
- move.l D3,-(SP)
-
- /* set up the JMP instruction at the end of the patch */
- lea @patchExit,A0
- move #JMP,(A0)
-
- /* get the old trap address */
- move #GetNextEvent,D0
- _GetTrapAddress
-
- /* set up the JMP instruction that calls the original trap */
- lea @origTrap,A1
- move #JMP,(A1)+
- move.l A0,(A1)
-
- /* get some space in the system heap */
- lea @last,A0
- lea @first,A1
- suba.l A1,A0
- move.l A0,D0
- move.l D0,D3 /* save for _BlockMove */
- _NewPtr SYS
- cmpi #memFullErr,D0
- beq.s @noPatch
- move.l A0,-(SP) /* save for _BlockMove */
-
- /* set the trap address to the space we just got in the system heap. */
- move #GetNextEvent,D0
- _SetTrapAddress
-
- /* now move it into place */
- lea @first,A0
- move.l (SP)+,A1
- move.l D3,D0
- _BlockMove
-
- @noPatch move.l (SP)+,D3
- rts
-
-
- /*
- * Here's the new _GetNextEvent. It calls the existing _GetNextEvent
- * and then checks if a keyDown or autoKey event is being reported.
- */
-
- @first lea @exitAddress,A0
- move.l (SP)+,(A0) /* save original return address */
- lea @eventPtr,A0
- move.l (SP),(A0) /* save ptr to event record */
- pea @tailPatch /* return to our routine */
-
- @origTrap nop /* JMP to original trap */
- nop
- nop
-
- @tailPatch lea @eventPtr,A0
- move.l (A0),A0
-
- move what(A0),D0 /* is it a keyDown or autoKey? */
- cmpi #keyDown,D0
- beq.s @isKeyDown
- cmpi #autoKey,D0
- bne.s @patchExit
-
- @isKeyDown move modifiers(A0),D0
- andi #shiftKey+alphaLock+optionKey+cmdKey,D0
- eori #shiftKey+alphaLock,D0
- bne.s @patchExit
-
- move.l message(A0),D0
- cmpi.b #'A',D0
- bmi.s @patchExit
- cmpi.b #'Z',D0
- bgt.s @patchExit
- addi.b #'a'-'A',D0
- move.l D0,message(A0)
-
- @patchExit nop /* return to original caller via long JMP */
- @exitAddress nop
- nop
-
- @eventPtr dc.l 0 /* storage for event record ptr */
-
- @last
- }
- }